<?php

require_once("Layout/controllersPageLayout.php");
require_once("Lib/DatabaseLib.php");
require_once("Lib/Admin.php");

if(isset($_POST["InputPass"]))
{
	$db = new DatabaseManager();
	$db->Connect(true);
	$admin = new Admin($db);
	if($admin->login($db, $_POST["InputPass"]))
		Utils::sendTo("index.php");
	else
	{
		$h = '<br/><br/><h2 align="center" style="color:red;">La password inserita non &egrave; corretta!</h2>'.
			 '<br/><br/><form name="login" id="login" method="POST" action="login.php" align="center">'.
			 '<h2>Password:</h2> <input type="password" name="InputPass" autofocus /><br/><br/>'.
			 '<table id="buttons"><tr><td><p align="center"><input type="submit" value="Accedi" /></p></td></tr></table>';
		$f = '</form>';
		printGenericPage("Accesso", "Inserire la password amministratore per accedere", array(),$h,$f);
	}
}
else
{
	$h = '<br/><br/><form name="login" id="login" method="POST" action="login.php" align="center">'.
	     '<h2>Password:</h2> <input type="password" name="InputPass" autofocus /><br/><br/>'.
		 '<table id="buttons"><tr><td><p align="center"><input type="submit" value="Accedi" /></p></td></tr></table>';
	$f = '</form>';
	printGenericPage("Accesso", "Inserire la password amministratore per accedere", array(),$h,$f);
}

?>
